<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改密码</title>
    <script type="text/javascript" src="../static/jquery-easyui-1.5.5/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="../static/jquery-easyui-1.5.5/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../static/toastr/toastr.min.css">
    <script type="text/javascript" src="../static/jquery-easyui-1.5.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../static/jquery-easyui-1.5.5/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../static/js/book/manage.js"></script>
    <script type="text/javascript" src="../static/js/custom.js"></script>
    <script type="text/javascript" src="../static/toastr/toastr.min.js"></script>
    <script type="text/javascript" src="../static/js/validate.js"></script>
</head>
<body>
<div style="margin: 280px 35%">
<!-- <form action="save" method="post" id="ff">
    <input name="id" data-th-value="${model.id}" type="hidden">
    <input name="role" data-th-value="${role}" type="hidden">
    <p>
        <input id="password" name="password" class="easyui-passwordbox" data-options="
        width: 250,
        label: '原密码',
        labelPosition: 'before',
        labelAlign: 'right',
        required: true,
        prompt: '请输入密码',
        missingMessage: '您还没有输入密码呃~~',
        showEye: false
    ">
    </p>
    <p><input id="pwd" name="pwd" class="easyui-passwordbox" data-options="
        width: 250,
        label: '新密码',
        labelPosition: 'before',
        labelAlign: 'right',
        prompt: '请输入新密码',
        required: true,
        missingMessage: '您还没有输入新密码呃~~',
        showEye: false
    "></p>
       <p><input id="rpwd" name="rpwd" class="easyui-passwordbox" data-options="
        width: 250,
        label: '重新输入',
        labelPosition: 'before',
        labelAlign: 'right',
        prompt: '请确认新密码',
        required: true,
        missingMessage: '您还没有输入新密码呃~~',
        showEye: false
    "></p>
    <div id="btn">
        <a class="easyui-linkbutton" href="#">确定修改</a>
    </div>
</form> -->
<form action="save" method="post" id="ff">
    <input name="id" data-th-value="${model.id}" type="hidden">
    <input name="role" data-th-value="${role}" type="hidden">
<p><input id="oldpassword" name="oldpassword" class="easyui-passwordbox" style="width: 250px;"
    label="原密码" labelPosition="before" labelAlign="right" prompt="请输入原密码" showEye=false delay=200 
     required="true"/><span id="info"></span></p>
     <!-- validType="checkpwd" -->
<p><input id="password" name="password" class="easyui-passwordbox" style="width: 250px;"
    label="新密码" labelPosition="before" labelAlign="right" prompt="请确认新密码" showEye=false
    validType="length[4,32]" required="true"/></p>
<p>
<input name="repassword" id="repassword" class="easyui-passwordbox" style="width: 250px;"
    label="重新输入" labelPosition="before" labelAlign="right" prompt="请确认新密码" showEye=false
    required="true" validType="equalTo['#password']" invalidMessage="两次输入密码不匹配"/>
</p>
    <div id="btn">
        <a class="easyui-linkbutton" href="#">确定修改</a>
    </div>
    </form> 
<script type="text/javascript">
var f;
$.extend($.fn.validatebox.defaults.rules, {    
    checkpwd: {    
        validator: function(value,param){    
        	var txt = value;
        	$.ajaxSettings.async = false;
        	$.post("checkpwd",{oldpassword: txt, id: [[${model.id}]]}, function(data) {
				 f = data.success;
        		$("#info").html(data.msg);
				
			});
        	$.ajaxSettings.async = true;
        	return f;
        },    
        message: '原密码错误~~'
    }    
});

$(function() {
	   $('#btn a').click(function() {
        console.log('你点击额');

        var p = $("#oldpassword").val();
        $.post("checkpwd",{oldpassword: p, id: [[${model.id}]]}, function(data) {
        	console.log(data.msg);
        	if(data.success) {
                $.messager.confirm('确认对话框', '您想要修改密码吗？', function(r){
                    if (r){
                        $('#ff').form('submit', {
                            url: 'editPassword',
                            onSubmit: function() {
                                console.log("提交之间");
                            },
                            success: function(data) {
                                var data = eval('(' + data + ')');
                                if(data.success) {
                                    console.log(data.msg);
                                    toastr.success(data.msg);
                                    $.messager.alert('提示','密码修改成功之后请重新登录','info', function() {
                                        $(window).attr('location','../logout');
                                    });   
                                } else {
                                    console.log(data.success);
                                    toastr.error(data.msg); 
                                }
                            }
                        });
                    };
                });
        		

        	} else {
        		$.messager.alert("提示", "原密码不正确哦~~", "info");
	            $("#info").html("<span style='color: red;'>"+data.msg+"</span>");
        	}
       });
        

    });
	   
});


</script>
</div>
</body>
</html>